package com.mapper.test.service;

import com.mapper.test.entity.Employee;
import com.mapper.test.mapper.EmployeeMapper;
import com.mapper.test.mapper.MyEmployeeMapper;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author liuziyang
 * @create 2019-06-02 21:53
 */
@Service
public class EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private MyEmployeeMapper myEmployeeMapper;


    public Employee getOne(Employee employeeQueryCondition) {
        return employeeMapper.selectOne(employeeQueryCondition);
    }

    public Employee getEmployeeById(Integer id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    public boolean isExists(Integer id) {
        return employeeMapper.existsWithPrimaryKey(id);
    }

    public int saveEmployee(Employee employee) {
        return employeeMapper.insert(employee);
    }

    public int saveSelectiveEmployee(Employee employee) {
        return employeeMapper.insertSelective(employee);
    }

    public int updateEmployeeSelective(Employee employee) {
        return employeeMapper.updateByPrimaryKeySelective(employee);
    }

    public int deleteEmployee(Employee employee) {
        return employeeMapper.delete(employee);
    }

    public int deleteEmployeeByPrimaryKey(Integer id) {
        return employeeMapper.deleteByPrimaryKey(id);
    }

    public List<Employee> getEmployeeListByExample(Example example) {
        return employeeMapper.selectByExample(example);
    }

    public List<Employee> getEmployeeByRowBounds(RowBounds rowBounds) {
        return employeeMapper.selectByRowBounds(null, rowBounds);
    }

    public void batchUpdateEmp(List<Employee> employees) {
        myEmployeeMapper.batchUpdate(employees);
    }
}
